home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / skeleton < prev    next >
Text File  |  2008-10-14  |  4KB  |  156 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          skeleton
  4. # Required-Start:    $remote_fs
  5. # Required-Stop:     $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Example initscript
  9. # Description:       This file should be used to construct scripts to be
  10. #                    placed in /etc/init.d.
  11. ### END INIT INFO
  12.  
  13. # Author: Foo Bar <foobar@baz.org>
  14. #
  15. # Please remove the "Author" lines above and replace them
  16. # with your own name if you copy and modify this script.
  17.  
  18. # Do NOT "set -e"
  19.  
  20. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  21. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  22. DESC="Description of the service"
  23. NAME=daemonexecutablename
  24. DAEMON=/usr/sbin/$NAME
  25. DAEMON_ARGS="--options args"
  26. PIDFILE=/var/run/$NAME.pid
  27. SCRIPTNAME=/etc/init.d/$NAME
  28.  
  29. # Exit if the package is not installed
  30. [ -x "$DAEMON" ] || exit 0
  31.  
  32. # Read configuration variable file if it is present
  33. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  34.  
  35. # Load the VERBOSE setting and other rcS variables
  36. . /lib/init/vars.sh
  37.  
  38. # Define LSB log_* functions.
  39. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  40. . /lib/lsb/init-functions
  41.  
  42. #
  43. # Function that starts the daemon/service
  44. #
  45. do_start()
  46. {
  47.     # Return
  48.     #   0 if daemon has been started
  49.     #   1 if daemon was already running
  50.     #   2 if daemon could not be started
  51.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  52.         || return 1
  53.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  54.         $DAEMON_ARGS \
  55.         || return 2
  56.     # Add code here, if necessary, that waits for the process to be ready
  57.     # to handle requests from services started subsequently which depend
  58.     # on this one.  As a last resort, sleep for some time.
  59. }
  60.  
  61. #
  62. # Function that stops the daemon/service
  63. #
  64. do_stop()
  65. {
  66.     # Return
  67.     #   0 if daemon has been stopped
  68.     #   1 if daemon was already stopped
  69.     #   2 if daemon could not be stopped
  70.     #   other if a failure occurred
  71.     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  72.     RETVAL="$?"
  73.     [ "$RETVAL" = 2 ] && return 2
  74.     # Wait for children to finish too if this is a daemon that forks
  75.     # and if the daemon is only ever run from this initscript.
  76.     # If the above conditions are not satisfied then add some other code
  77.     # that waits for the process to drop all resources that could be
  78.     # needed by services started subsequently.  A last resort is to
  79.     # sleep for some time.
  80.     start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  81.     [ "$?" = 2 ] && return 2
  82.     # Many daemons don't delete their pidfiles when they exit.
  83.     rm -f $PIDFILE
  84.     return "$RETVAL"
  85. }
  86.  
  87. #
  88. # Function that sends a SIGHUP to the daemon/service
  89. #
  90. do_reload() {
  91.     #
  92.     # If the daemon can reload its configuration without
  93.     # restarting (for example, when it is sent a SIGHUP),
  94.     # then implement that here.
  95.     #
  96.     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  97.     return 0
  98. }
  99.  
  100. case "$1" in
  101.   start)
  102.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  103.     do_start
  104.     case "$?" in
  105.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  106.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  107.     esac
  108.     ;;
  109.   stop)
  110.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  111.     do_stop
  112.     case "$?" in
  113.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  114.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  115.     esac
  116.     ;;
  117.   #reload|force-reload)
  118.     #
  119.     # If do_reload() is not implemented then leave this commented out
  120.     # and leave 'force-reload' as an alias for 'restart'.
  121.     #
  122.     #log_daemon_msg "Reloading $DESC" "$NAME"
  123.     #do_reload
  124.     #log_end_msg $?
  125.     #;;
  126.   restart|force-reload)
  127.     #
  128.     # If the "reload" option is implemented then remove the
  129.     # 'force-reload' alias
  130.     #
  131.     log_daemon_msg "Restarting $DESC" "$NAME"
  132.     do_stop
  133.     case "$?" in
  134.       0|1)
  135.         do_start
  136.         case "$?" in
  137.             0) log_end_msg 0 ;;
  138.             1) log_end_msg 1 ;; # Old process is still running
  139.             *) log_end_msg 1 ;; # Failed to start
  140.         esac
  141.         ;;
  142.       *)
  143.           # Failed to stop
  144.         log_end_msg 1
  145.         ;;
  146.     esac
  147.     ;;
  148.   *)
  149.     #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  150.     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  151.     exit 3
  152.     ;;
  153. esac
  154.  
  155. :
  156.